/*
 * @lc app=leetcode.cn id=633 lang=typescript
 *
 * [633] 平方数之和
 */

// @lc code=start
function judgeSquareSum(c) {
    let r = Math.floor(Math.sqrt(c))
    let l = 0

    while (l <= r) {
        const sum = l*l + r*r
        if (sum == c) {
            return true
        }
        else if (sum > c) {
            r--
        }
        else {
            l++
        }
    }

    return false
};
// @lc code=end

console.log(
    judgeSquareSum(3)
)
